package com.ruoyi.admin.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Random;

public class CommonUtil {
    //创建订单号(年月日时分秒毫秒)
    public static String createOrderCode(){
        Calendar calendar=Calendar.getInstance();
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String orderCode=simpleDateFormat.format(calendar.getTime());
        return orderCode+getRandomNum(6);
    }
    //生成指定位数的随机字符串
    public static String getRandomNum(Integer num){
        Random random=new Random();
        StringBuffer stringBuffer=new StringBuffer();
        for (int i=0;i<num;i++){
            stringBuffer.append(random.nextInt(10));
        }
        return stringBuffer.toString();
    }
}
